package com.goldgov.utils;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.scheduler.PriorityScheduler;
/**
* description: webMagic爬取深度设置
*/
public class LevelLimitScheduler extends PriorityScheduler {
   /**
    * 构造方法
    */
   private int levelLimit = 0;
   public LevelLimitScheduler(int levelLimit) {
      this.levelLimit = levelLimit;
   }
   @Override
   public synchronized void push(Request request, Task task) {
      //深度判断
      if (((Integer) request.getExtra("_level")) <= levelLimit) {
         super.push(request, task);
      }
   }
}